package stack;

class Stack{
	 static int DEFAULT_SIZE = 10;
	
	private int[] elements;
	private int top;
	
	public Stack(int size){
		elements = new int[size];
		top=0;
	}
	
	public Stack(){
		elements = new int[Stack.DEFAULT_SIZE];
		top =0;
	}
	
	public void pushElement(int element){
		if(top<elements.length){
		 elements[top++] = element;
		}else{
			throw new IllegalStateException("Stack is full");
		}
	}
	
	public void popElement(){
		if(top==0){
			throw new IllegalStateException("Stack is empty");
		}else{
			top--;
		}
	}
	
}
public class StackImpl {

	public static void main(String[] args) {
		Stack stack = new Stack(3);
		try{
			stack.pushElement(1);
			stack.pushElement(2);
			stack.pushElement(3);
			stack.pushElement(4);
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		try{
			stack.popElement();
			stack.popElement();
			stack.popElement();
			stack.popElement();
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
	}

}
